﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dapper;
using JohnnySins.Entities;

namespace JohnnySins.DAL.Repositories
{
    public class LogRepository: BaseRepository<Log>
    {
        protected override string TableName
        {
            get { return "[Log]"; }
        }

        public void SaveLog(string eventMessage, string stackTrace, string currentUser, string path, string queryString, string browser, string userHostAddress, string urlReferrer)
        {
            Connection.Execute(string.Format(@"insert into Log([EventMessage], [StackTrace], [CurrentUser], [Path], [QueryString], [Browser], [UserHostAddress], [UrlReferrer])
                values('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}')",
                eventMessage, stackTrace, currentUser, path, queryString, browser, userHostAddress, urlReferrer));

        }

        public void SaveLogLogin(string loginName, string loginPassword, string epochAnswer, string epochEx, bool success, string browser, string userHostAddress)
        {
            Connection.Execute(string.Format(@"insert into LogLogin([LoginName], [LoginPassword], [EpochAnswer], [EpochEx], [Success], [Browser], [UserHostAddress])
                values('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')",
                loginName, loginPassword, epochAnswer, epochEx, success, browser, userHostAddress));
        }

        public void RegisterUserLog(string eventMessage, string stackTrace, string currentUser, string path, string queryString, string browser, string userHostAddress, string urlReferrer)
        {
            Connection.Execute(string.Format(@"insert into Log([EventType], [EventMessage], [StackTrace], [CurrentUser], [Path], [QueryString], [Browser], [UserHostAddress], [UrlReferrer])
                values('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}')",
                "REG", eventMessage, stackTrace, currentUser, path, queryString, browser, userHostAddress, urlReferrer));

        }
    }
}
